<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AlterOrderAddDeliverType extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        $cFunc = function (Blueprint $table) {
            $table->integer('distributionAmount')->default(0)->after('isSelfDelivery')->comment('渠道佣金');
            $table->string('distributionPer')->default('')->after('isSelfDelivery')->comment('渠道佣金占比 文字');
            $table->integer('distributionId')->default(0)->after('isSelfDelivery')->comment('渠道佣金 ID');
            $table->tinyInteger('deliveryType')->default(0)->after('isSelfDelivery')
                  ->comment('配送类型0 无 1 自配送 2 渠道配送');

            $table->index('distributionId', 'idx_distributionId');
        };

        // 分表库
        for ($i = 0; $i <= 99; $i++) {
            $this->name = '_' . str_pad($i, 3, 0, STR_PAD_LEFT);
            Schema::connection("mysqlOrder")->table('order' . $this->name, $cFunc);
            Schema::connection("mysqlOrder_2")->table('order' . $this->name, $cFunc);
            dump($this->name . '已添加');
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        $cFunc = function (Blueprint $table) {
            $table->dropColumn('distributionAmount');
            $table->dropColumn('distributionPer');
            $table->dropColumn('distributionId');
            $table->dropColumn('deliveryType');
        };

        // 分表库
        for ($i = 0; $i <= 99; $i++) {
            $this->name = '_' . str_pad($i, 3, 0, STR_PAD_LEFT);
            Schema::connection("mysqlOrder")->table('order' . $this->name, $cFunc);
            Schema::connection("mysqlOrder_2")->table('order' . $this->name, $cFunc);
            dump($this->name . '已删除');
        }
    }
}
